﻿package net.wangit.user.admin;

import java.util.HashMap;
import java.util.Map;

import net.wangit.util.ArrayUtil;


public class Admin {

	private String id;
	private String name;
	private boolean authorizationEnabled;
	private String organizations[];
	private String groups[];
	private String roles[];
	private String indirectRoles[];
	private int allRolesCount;
	private Map privileges;

	public Admin(String id) {
		this.id = id;
	}

	public String getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	protected void setName(String name) {
		this.name = name;
	}

	public String[] getOrganizations() {
		return organizations;
	}

	protected void setOrganizations(String organizations[]) {
		this.organizations = organizations;
	}

	public boolean containsOrganization(String organizationId) {
		return ArrayUtil.find(organizations, organizationId) >= 0;
	}

	public String[] getGroups() {
		return groups;
	}

	protected void setGroups(String groups[]) {
		this.groups = groups;
	}

	public boolean containsGroup(String groupId) {
		return ArrayUtil.find(groups, groupId) >= 0;
	}

	public String[] getRoles() {
		return roles;
	}

	protected void setRoles(String roles[]) {
		this.roles = roles;
	}

	public boolean containsRole(String roleId) {
		return ArrayUtil.find(roles, roleId) >= 0;
	}

	public Map getPrivileges() {
		return privileges;
	}

	protected void setPrivileges(Map privileges) {
		this.privileges = privileges;
	}

	public String[] getIndirectRoles() {
		return indirectRoles;
	}

	public boolean containsIndirectRole(String roleId) {
		return ArrayUtil.find(indirectRoles, roleId) >= 0;
	}

	protected void setIndirectRoles(String indirectRoles[]) {
		this.indirectRoles = indirectRoles;
	}

	public int getAllRolesCount() {
		return allRolesCount;
	}

	protected void setAllRolesCount() {
		Map allRoles = new HashMap();
		for (int i = 0; i < roles.length; i++)
			allRoles.put(roles[i], null);

		for (int i = 0; i < indirectRoles.length; i++)
			allRoles.put(indirectRoles[i], null);

		allRolesCount = allRoles.size();
	}

	public boolean isAuthorizationEnabled() {
		return authorizationEnabled;
	}

	protected void setAuthorizationEnabled(boolean authorizationEnabled) {
		this.authorizationEnabled = authorizationEnabled;
	}
}
